export default function api(api = 'user-center', action, params = {}, title) {
	return new Promise((resolve, reject) => {
		if (title) {
			uni.showLoading({
				title: title,
				mask:true
			});
		}
		uniCloud.callFunction({
			name: api,
			data: {
				action,
				params
			}
		}).then(({
			result
		}) => {
			if (result.code == 1001) {
				uni.showLoading({
					title: "登陆过期，重新登陆中。。"
				})
				uni.login({
					provider: 'weixin'
				}).then(code => {
					code = code[1].code
					this.$api('user-center', 'loginByWeixin', {
						code,
						invitation: 0
					}).then(res => {
						if (res.code === 0) {
							uni.hideLoading()
							// 如果使用2.7.15及以上版本建议存为uni_id_token
							uni.setStorageSync('uniIdToken', res.token)
							res.userInfo.sessionKey = res.sessionKey
							this.$store.commit('user/login', res.userInfo)
							uni.setStorageSync('uni_id_token_expired', res.tokenExpired)
						}
					})
				})
			} else {
				resolve(result)
				if (title) {
					uni.hideLoading()
				}
			}
		})
	})
}
